package com.zlx.xBiaoShop.mapper;

import com.zlx.xBiaoShop.entity.Goods;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsMapper {

    @Select("SELECT * FROM `goods` ORDER BY publish_date LIMIT 1,4")
    List<Goods> getNewGoods();


    @Select("SELECT * FROM `goods` ORDER BY sales_volumes DESC LIMIT 1,4")
    List<Goods> getHotGoods();

    @Select("SELECT " +
            "g.*, " +
            "s.store_name  " +
            "FROM " +
            "goods g " +
            "LEFT JOIN store s ON g.store_id = s.id  " +
            "WHERE " +
            "g.id IN(SELECT syg.goods_id FROM sys_user_goods syg WHERE syg.user_id =#{userId})")
    List<Goods> findGoodsListByUserId(Integer userId);

    @Select("SELECT " +
            "g.*, " +
            "s.store_name  " +
            "FROM " +
            "goods g " +
            "LEFT JOIN store s ON g.store_id = s.id ")
    List<Goods> selectAll();

    @Select("SELECT * FROM `goods` WHERE id = #{id}")
    Goods findGoodsById(Integer id);

    @Select("SELECT * FROM `goods` WHERE type_id = #{typeId}")
    List<Goods> selectBytypeId( Integer typeId);

    @Update("UPDATE goods SET look = #{look} WHERE id = #{id}")
    void updateLookById(@Param("id")Integer id,@Param("look") Integer look);

    @Select("SELECT * FROM `goods` WHERE good_name LIKE CONCAT('%',#{goodsName},'%')")
    List<Goods> getGoodsPageByGoodsName(String goodsName);
}
